import { PlusOutlined } from '@ant-design/icons';
import {
    ActionType,
    ModalForm,
    ProForm,
    ProFormDateRangePicker,
    ProFormSelect,
    ProFormText,
} from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';
import {ProFormDateTimeRangePicker, ProFormDigit} from "@ant-design/pro-form";
import {addChatter} from "@/services/chatter";
import {useRef, useState} from "react";

const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(true);
        }, time);
    });
};
export default (props) => {
    const [form] = Form.useForm<{ name: string; company: string }>();
    const [updateModalForm, setUpdateModalForm] = useState();
    const {actionRef} = props;
    return (
        <ModalForm<{
            name: string;
            company: string;
        }>
            title="Add chatter"
            trigger={
                <Button type="primary" disabled={false}>
                    <PlusOutlined/>
                    Add
                </Button>
            }
            form={form}
            visible={updateModalForm}
            onVisibleChange={setUpdateModalForm}
            autoFocusFirstInput
            modalProps={{
                destroyOnClose: true,
                onCancel: () => console.log('run'),
            }}
            submitTimeout={2000}
            onFinish={async (values) => {

                console.log(values);
                const workingHours = values.startHour1+"-"+values.endHour1+"/"+values.startHour2+"-"+values.endHour2;
                const params={
                    "account":values.account,
                    "nickName":values.nickName,
                    "password":values.password,
                    "jobType":values.jobType,
                    "gender":values.gender,
                    "workingHours":workingHours
                }
                console.log(params);
                addChatter(params).then(res=>{
                    setUpdateModalForm(false)
                    message.success('Success');
                    if (actionRef.current) {
                        actionRef.current.reload();
                    }
                })
                return false;
            }}
        >
            <ProForm.Group>
                <ProFormText
                    width="md"
                    name="account"
                    label="CID"
                    rules={[{required: true}]}
                />

            </ProForm.Group>
            <ProFormText
                width="md"
                name="password"
                label="Password"
                rules={[{required: true}]}
            />
            <ProFormText
                width="md"
                name="nickName"
                label="Name"
                rules={[{required: true}]}
            />
            <ProForm.Group>
                <ProFormSelect
                    request={async () => [
                        {
                            value: '1',
                            label: 'male',
                        },
                        {
                            value: '2',
                            label: 'female',
                        },
                    ]}
                    width="md"
                    name="gender"
                    label="Gender"
                    rules={[{required: true}]}
                />

            </ProForm.Group><ProForm.Group>
                <ProFormSelect
                    request={async () => [
                        {
                            value: '1',
                            label: 'fullTime',
                        },
                        {
                            value: '2',
                            label: 'partTime',
                        },
                    ]}
                    width="md"
                    name="jobType"
                    label="JobType"
                    rules={[{required: true}]}
                />

            </ProForm.Group>
            <ProForm.Group>
                <ProFormDigit
                    label="StartHour1"
                    name="startHour1"
                    min={0}
                    max={24}
                    fieldProps={{ precision: 0 }}
                    rules={[{required: true}]}
                />
                <ProFormDigit
                    label="EndHour1"
                    name="endHour1"
                    min={0}
                    max={24}
                    fieldProps={{ precision: 0 }}
                    rules={[{required: true}]}
                />
            </ProForm.Group>
            <ProForm.Group>
                <ProFormDigit
                    label="StartHour2"
                    name="startHour2"
                    min={0}
                    max={24}
                    fieldProps={{ precision: 0 }}
                    rules={[{required: true}]}
                />
                <ProFormDigit
                    label="EndHour2"
                    name="endHour2"
                    min={0}
                    max={24}
                    fieldProps={{ precision: 0 }}
                    rules={[{required: true}]}
                />
            </ProForm.Group>
        </ModalForm>
    );
};